<template>
  <div class="about">
    <div class="about_item" v-for="(item,index) in this.$store.state.cartList" :key="index">
      <div class="item_container">
        <input type="checkbox" :checked="item.checked" @click="changeck(index)">
        <img :src="item.item.productImage" height="100px">
      </div>
      <div class="desc_container">
        <p>商品名称:{{item.item.productName}}</p>
        
        <p>单价:{{item.item.salePrice}}</p>
        <p>数量:{{item.num}}</p>
        <p>小计:{{item.item.salePrice*item.num}}</p>
      </div>
      <el-button  @click="del(index)">删除</el-button>
    </div>
    <div class="bottom">
      全选:
      <input type="checkbox" @click="checkAll($event)">
      总价:<span>{{this.allTotal}}</span>
    </div>
  </div>
</template>

<script>
export default {
  data(){
    return{
      allTotal:0
    }
  },
  methods:{
    changeck(index){
    this.$store.commit("CHANGECK",index)
    },
    del(index){
      this.$store.commit("DELETE",index)
    },
    checkAll(e){
      this.allTotal = 0;
      this.$store.state.cartList.forEach(el=>{
        if(e.target.checked){
          el.checked = true;
          this.allTotal+=el.item.salePrice * el.num
        }else{
          el.checked = false
        }
      })
    },
  },
}
</script>
<style scoped>
.about
{
  width: 100vw;
  height: 100vh;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
}
.about_item
{
  width: 1000px;
  height: 100px;
  border: 1px solid red;
  display: inline-flex;
  justify-content: space-around;
  margin-top: 20px;
}
.bottom
{
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  height: 100px;
  background-color: #fff;
}
.desc_container p 
{
  margin-top: 4px;
}
</style>